//
//  CartTableViewCell.m
//  TestByFF
//
//  Created by hanxifeng on 16/7/20.
//  Copyright © 2016年 haixu. All rights reserved.
//

#import "CartTableViewCell.h"

@interface CartTableViewCell()
@property (nonatomic,weak)UIImageView *iconView;
@property (nonatomic,weak)UIButton *cartBtn;
@end

@implementation CartTableViewCell

-(instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier{
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        UIImageView *img = [[UIImageView alloc] initWithFrame:CGRectMake(20,0, 50, 50)];
        self.iconView = img;
        [self.contentView addSubview:img];
        
        UIButton *buyBtn = [[UIButton alloc] initWithFrame:CGRectMake(SCREEN_WIDTH - 20 - 80, 10, 80, 30)];
        buyBtn.backgroundColor = [UIColor redColor];
        [buyBtn addTarget:self action:@selector(cartBtnClick:) forControlEvents:UIControlEventTouchUpInside];
        self.cartBtn = buyBtn;
        [buyBtn setTitle:@"add购物车" forState:UIControlStateNormal];
        [self.contentView addSubview:buyBtn];
    }
    return self;
}

+(instancetype)customCellWithTableView:(UITableView *)tableView{
    static NSString *identifier = @"cartCell";
    CartTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:identifier];
    //创建cell
    if (cell==nil) {
        cell = [[CartTableViewCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:identifier];
        cell.selectionStyle = UITableViewCellSelectionStyleNone;
    }
    return cell;
}

-(void)setDataDic:(NSDictionary *)dataDic{
    self.iconView.image = [UIImage imageNamed:[dataDic objectForKey:@"iconimg"]];
}

-(void)cartBtnClick:(UIButton *)cartBtn{
    if (self.cartBtnClickBlock!=nil) {
        self.cartBtnClickBlock(self.iconView,self);
    }
}
-(void)cartBtnClickBlock:(CartBtnClickBlock)block{
    self.cartBtnClickBlock = block;
}
@end
